package gdma.hqdes.bean;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import common.lang.TreeNode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.util.*;

/**
 * @Author wangyue
 * @Version 3.0
 * @Date 2024-07-13
 */

@Data
public class Unit implements TreeNode<Unit>,  Serializable {
    public static final int SCOPE_NATIONAL = 0;
    public static final int SCOPE_PROVINCIAL = 1;
    public static final int SCOPE_MUNICIPAL = 2;
    public static final int SCOPE_COUNTY = 3;

    public static Map<Integer, String> SCOPE_TEXTS = new HashMap<Integer, String>() {{
        put(SCOPE_NATIONAL, "全国");
        put(SCOPE_PROVINCIAL, "省级");
        put(SCOPE_MUNICIPAL, "地市级");
        put(SCOPE_COUNTY, "区县级");
    }};

    public static Map<String, String> AREA_TEXTS = new HashMap<String, String>() {{
        put("Z", "珠三角");
        put("Y", "粤东西北");
    }};

    @ApiModelProperty("id")
    @TableId
    Long id;

    @ApiModelProperty("状态：0=正常, -1=停用")
    Integer status;

    @ApiModelProperty("单位名称")
    String name;

    @ApiModelProperty("单位层级：0=全国,  1=省级,  2=地市级,  3=区县级")
    Integer scope;

    public String getScopeText() {
        return scope != null ? SCOPE_TEXTS.get(scope) : null;
    }

    @ApiModelProperty("区域标签：Z=珠三角，Y=粤东西北")
    String areaTag;

    public String getAreaText() {
        return areaTag != null ? AREA_TEXTS.get(areaTag) : null;
    }

    @ApiModelProperty("上级单位id")
    Long parentId;

    @ApiModelProperty("权重可设置0-100，为空则为等分权重")
    Float weight;

    @ApiModelProperty("短名称，要和地图数据中城市名称的键值一致：如”广州市“不能仅写成”广州“")
    String shortName;

    @ApiModelProperty("短名前缀，例如：gd_gz_")
    String shortPrefix;

    @ApiModelProperty("联系人姓名")
    String contactName;

    @ApiModelProperty("联系人电话")
    String contactPhone;

    @ApiModelProperty("创建时间")
    Date createdTime;

    @ApiModelProperty("更新时间")
    Date updatedTime;

    @TableField(exist = false)
    @ApiModelProperty("提醒标志，该单位指标是否有当前登陆人员的待完成事项")
    Integer isNotifying;

    @TableField(exist = false)
    @JsonIgnore
    @ToString.Exclude
    Unit parent;

    @TableField(exist = false)
    List<Unit> children;

    @Override
    public void addChild(Unit child) {
        if(children == null) children = new ArrayList<>();
        children.add(child);
    }

    @TableField(exist = false)
    HqdIndex index;

}
